package com.practice.library.Controller;

import jakarta.servlet.http.HttpSession;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RequestMapping("/user")
@RestController
public class UserController {
    @RequestMapping("/login")
    public String login(String userName, String password, HttpSession session){
        //1.参数校验
        //2.验证用户名和密码
        //3.存Session
        if(!StringUtils.hasLength(userName)||!StringUtils.hasLength(password)){
            System.out.println(userName);
            System.out.println(password);
            return "用户名或者密码不能为空";

        }
        System.out.println("2 我出现问题");

        //还未学习数据库的操作,暂且硬编码
        //写死Username='zhangsan'和password=123456
        if (!"zhangsan".equals(userName) ||!"123456".equals(password)) {
            System.out.println(userName);
            System.out.println(password);
            return "账号或者密码不正确";
        }
        System.out.println("3 我出现问题");

        //存储Session
        session.setAttribute("userName",userName);
        return "";

    }

}
